//
//  DatabaseConfig.swift
//  App
//
//  Created by 汤泽川 on 2019/3/25.
//

import Foundation
import Vapor
import FluentMySQL

public func DatabaseConfigure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
    // Register providers first
    try services.register(FluentMySQLProvider())
    let hostName : String
    #if os(OSX)
    hostName = "tzcccy.cn"
    #else
    hostName = "tzcccy.cn"
    #endif
    print("Host Name : \(hostName)")
    let mysqlConfig = MySQLDatabaseConfig(hostname: hostName, port: 3306, username: "vapor", password: "0054321", database: "vapor")
    let mysql = MySQLDatabase(config: mysqlConfig)
    
    // Register the configured MySQL database to the database config.
    var databases = DatabasesConfig()
    databases.add(database: mysql, as: .mysql)
    services.register(databases)
}
